import componentMap from "./alias";
export const getAllComponentList = () => {
  const allComponentList = [];
  const typeList = Object.keys(componentMap);
  typeList.forEach((type) => {
    const componentItem = componentMap[type];
    allComponentList.push(componentItem);
  });
  return allComponentList;
};

export const getAllGroupList = () => {
  const allComponentList = getAllComponentList();
  const groupList = [];
  allComponentList.forEach((item) => {
    const meta = item.getMeta();
    let groupItem = groupList.find((item) => {
      item.groupType === meta.groupType;
    });
    if (!groupItem) {
      groupItem = {
        groupType: meta.groupType,
        groupTitle: meta.groupTitle,
        list: [],
      };
      groupList.push(groupItem);
    }
    groupItem.list.push(meta);
  });
  return groupList;
};
export const getComponentInfo = (type) => {
  const componentItem = componentMap[type];
  return componentItem || {};
};

export const getDefaultConfig = (type) => {
  const component =  getComponentInfo(type) || {};
  return component?.getDefaultConfig() || {};
};

export const getConfigListMap = (type) => {
  const component = getComponentInfo(type) || {};
  return component?.getConfigListMap() || {
    style: [],
    data: [],
    interaction: [],
  };
};
export const getComponentMeta = (type) => {
  const componentItem = getComponentInfo(type);
  return componentItem.getMeta();
};
export const getComponent = (type, modelType) => {
  const componentItem = getComponentInfo(type);
  return componentItem.getComponent(modelType);
};
